#pragma once

#include "mccommonapi.h"

#include <iostream>
#include <string>
#include <vector>

namespace MCCommon
{
    
/****************************************
 * Write functions begin.
 ***************************************/
void MCAPI Write
(
    std::ostream& os,
    int iValue
);

void MCAPI Write
(
    std::ostream& os,
    short iValue
);

void MCAPI Write
(
    std::ostream& os,
    unsigned int iValue
);
   
void MCAPI Write
(
    std::ostream& os,
    bool bValue
);

void MCAPI Write
(
    std::ostream& os,
    long lValue
);
 
void MCAPI Write
(
    std::ostream& os,
    double dValue
);

void MCAPI Write
(
    std::ostream& os,
    const std::string& sValue
);
 
template< class T >
void MCAPI Write
(
    std::ostream& os,
    const std::vector< T >& viValues
)
{
    int size = (int)viValues.size();
    Write( os, size );

    for ( int i=0; i<size; i++ )
    {
        Write( os, viValues[i] );
    }
}
/****************************************
* Write functions end.
***************************************/


/****************************************
* Read functions begin.
***************************************/
bool MCAPI Read
(
    std::istream& is,
    int& iValue
);

bool MCAPI Read
(
    std::istream& is,
    short& iValue
);

bool MCAPI Read
(
    std::istream& is,
    unsigned int& iValue
);

bool MCAPI Read
(
    std::istream& is,
    long& iValue
);

bool MCAPI Read
(
    std::istream& is,
    double& dValue
);

bool MCAPI Read
(
    std::istream& is,
    std::string& sValue
);

bool MCAPI Read
(
    std::istream& is,
    bool& bValue
);

template<class T>
bool MCAPI Read
(
    std::istream& is,
    std::vector< T >& values
)
{
    bool isOK(false);

    int size = 0;
    isOK = Read( is, size );
    
    if ( isOK )
    {
        values.resize( size );
        for ( int i=0; i<size; i++ )
        {
            Read( is, values[i] );
        }
    }
    
    return isOK;
}
/****************************************
* Read functions end.
***************************************/

} // end of namespace MCCommon.